/*************************************************************************
	> File Name: monolith/core/macros.h
	> Author: dzhang
	> Mail: dong.zhang@ingenic.com 
	> Created Time: Sun 13 Dec 2020 04:37:55 PM CST
 ************************************************************************/

#ifndef _MONOLITH_CORE_MACROS_H_
#define _MONOLITH_CORE_MACROS_H_
#include <iostream>

// define namepsace
#define CC_NAME_SPACE_NAME ml
#define CC_NAME_SPACE_BEGIN namespace CC_NAME_SPACE_NAME{
#define CC_NAME_SPACE_END }// namespace ml
#define USING_NAME_SPACE using namespace CC_NAME_SPACE_NAME;

#if defined(_MSC_VER)
#if defined(BUILDING_ML_DLL)
#define ML_PUBLIC __declspec(dllexport)
#elif defined(USING_ML_DLL)
#define ML_PUBLIC __declspec(dllimport)
#else
#define ML_PUBLIC
#endif
#else
#define ML_PUBLIC __attribute__((visibility("default")))
#endif


#ifdef _MSC_VER
typedef signed __int8 int8;
typedef __int16 int16;
typedef __int32 int32;
typedef __int64 int64;

typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64;
#else
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
#endif

#define ML_PRINT(format, ...) printf(format, ##__VA_ARGS__)
#define ML_ERROR(format, ...) printf(format, ##__VA_ARGS__)

#define CLIP(x, y) (x < 0 ? 0 : (x > y ? y : x))

#define ALIMIN(x, y) ((x) < (y) ? (x) : (y))
#define ALIMAX(x, y) ((x) > (y) ? (x) : (y))

#define UP_DIV(x, y) (((x) + (y) - (1)) / (y))
#define ROUND_UP(x, y) (((x) + (y) - (1)) / (y) * (y))
#define ALIGN_UP4(x) ROUND_UP((x), 4)
#define ALIGN_UP8(x) ROUND_UP((x), 8)
#if (__arm__ || __aarch64__) && (defined(__ARM_NEON__) || defined(__ARM_NEON))
#define ML_USE_NEON
#endif


#define MAX_TENSOR_DIM 6
enum ML_DATA_FORMAT {
  ML_DATA_FORMAT_NCHW = 0,
  ML_DATA_FORMAT_NHWC = 1,
  ML_DATA_FORMAT_NC4HW4 = 2,
  ML_DATA_FORMAT_NHWC4 = 3,
  ML_DATA_FORMAT_UNKNOWN = 4,
  ML_DATA_FORMAT_MIN = ML_DATA_FORMAT_NCHW,
  ML_DATA_FORMAT_MAX = ML_DATA_FORMAT_UNKNOWN
};

enum DataType {
  DataType_DT_INVALID = 0,
  DataType_DT_FLOAT = 1,
  DataType_DT_DOUBLE = 2,
  DataType_DT_INT32 = 3,
  DataType_DT_UINT8 = 4,
  DataType_DT_INT16 = 5,
  DataType_DT_INT8 = 6,
  DataType_DT_STRING = 7,
  DataType_DT_COMPLEX64 = 8,
  DataType_DT_INT64 = 9,
  DataType_DT_BOOL = 10,
  DataType_DT_QINT8 = 11,
  DataType_DT_QUINT8 = 12,
  DataType_DT_QINT32 = 13,
  DataType_DT_BFLOAT16 = 14,
  DataType_DT_QINT16 = 15,
  DataType_DT_QUINT16 = 16,
  DataType_DT_UINT16 = 17,
  DataType_DT_COMPLEX128 = 18,
  DataType_DT_HALF = 19,
  DataType_DT_RESOURCE = 20,
  DataType_DT_VARIANT = 21,
  DataType_MIN = DataType_DT_INVALID,
  DataType_MAX = DataType_DT_VARIANT
};




#ifdef DEBUG
#define ML_ASSERT(x)                                            \
    {                                                            \
        int res = (x);                                           \
        if (!res) {                                              \
            printf("Error for %s, %d\n", __FILE__, __LINE__); \
            assert(res);                                         \
        }                                                        \
    }
#else
#define ML_ASSERT(x)                                            \
    {                                                            \
        int res = (x);                                           \
        if (!res) {                                              \
            printf("Error for %d\n", __LINE__); \
        }                                                        \
    }
#endif



CC_NAME_SPACE_BEGIN
/** protocol class. used to delete assignment operator. */
class NonCopyable {
public:
    NonCopyable()                    = default;
    NonCopyable(const NonCopyable&)  = delete;
    NonCopyable(const NonCopyable&&) = delete;
    NonCopyable& operator=(const NonCopyable&) = delete;
    NonCopyable& operator=(const NonCopyable&&) = delete;
};
CC_NAME_SPACE_END



#endif //_MONOLITH_CORE_MACROS_H_
